home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / source / src / graph / _ugraph.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  1.9 KB  |  83 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  _ugraph.c
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16. #include <LEDA/ugraph.h>
  17.  
  18.  
  19. //------------------------------------------------------------------------------
  20. // undirected graphs 
  21. //------------------------------------------------------------------------------
  22.  
  23. void  ugraph::print_edge(edge e,ostream& o) const
  24. { o <<   "[" << e->s->name << "]==";
  25.   print_edge_entry(o,e->data[0]);
  26.   o << "==[" << e->t->name << "]";
  27.  }
  28.  
  29. // ugraph subgraph constructors:
  30.  
  31. ugraph::ugraph(ugraph& G, const list<node>& nl, const list<edge>& el)
  32. { // construct subugraph (nl,el) of ugraph G
  33.  
  34.   parent = &G;
  35.   node v,w;
  36.   edge e;
  37.  
  38.   node* N = new node[G.max_n_index+1];
  39.  
  40.   forall(v,nl)
  41.    { if (graph_of(v) != parent) 
  42.       error_handler(1,"ugraph: illegal node in subgraph constructor");
  43.      N[v->name] = new_node(v);
  44.     }
  45.  
  46.   forall(e,el)
  47.    { v = source(e);
  48.      w = target(e);
  49.      if ( graph_of(e)!= parent || N[v->name]==0 || N[w->name]==0 ) 
  50.       error_handler(1,"ugraph: illegal edge in subgraph constructor");
  51.      new_edge(N[v->name],N[w->name],e);
  52.     }
  53.  
  54.   delete N;
  55.  
  56.  }
  57.  
  58. ugraph::ugraph(ugraph& G, const list<edge>& el)
  59. { // construct subgraph of ugraph G with edgelist el 
  60.  
  61.   node  v,w;
  62.   edge  e;
  63.   node* N = new node[G.max_n_index+1];
  64.  
  65.   forall_nodes(v,G) N[v->name] = 0;
  66.  
  67.   parent = &G;
  68.  
  69.   forall(e,el)
  70.    { v = source(e);
  71.      w = target(e);
  72.      if (N[v->name] == 0) N[v->name] = new_node(v);
  73.      if (N[w->name] == 0) N[w->name] = new_node(w);
  74.      if ( graph_of(e) != parent )
  75.        error_handler(1,"ugraph: illegal edge in subgraph constructor");
  76.      new_edge(N[v->name],N[w->name],e);
  77.     }
  78.  
  79.   delete N;
  80.  
  81.  }
  82.